package com.nefu.softlab.xjwc.controller;

import com.nefu.softlab.xjwc.utils.JSONResult;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author : Ar1es
 * @date : 2020/1/16
 * @since : Java 8
 */
@RestControllerAdvice
public class ExceptionController {

    @ExceptionHandler(UnauthorizedException.class)
    public JSONResult handleShiroException(Exception e) {
        return JSONResult.errorRolesMessage(e.getMessage());
    }

    @ExceptionHandler(AuthorizationException.class)
    public JSONResult AuthorizationException(Exception e) {
        return JSONResult.errorMessage(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public JSONResult Exception(Exception e) {
        return JSONResult.errorMessage(e.getMessage());
    }
}
